package com.kuaiditu.assistant.ui.main;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kuaiditu.assistant.R;
import com.kuaiditu.assistant.entity.TaskSquareEn;
import com.kuaiditu.assistant.util.JudgeExpressUtil;
import com.kuaiditu.assistant.util.OrderStateUtil;

import java.text.SimpleDateFormat;
import java.util.List;

import cn.iwgang.simplifyspan.SimplifySpanBuild;
import cn.iwgang.simplifyspan.unit.SpecialTextUnit;

/**
 * Created by Eenie on 2017/8/30.
 * Email: eeniework@gmail.com
 * Des:
 */

public class CompleteTaskAdapter extends BaseQuickAdapter<TaskSquareEn,BaseViewHolder> {

    private SimpleDateFormat mSimpleDateFormat;

    public CompleteTaskAdapter(@Nullable List<TaskSquareEn> data) {
        super(R.layout.item_complete_task, data);
        mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    protected void convert(BaseViewHolder helper, TaskSquareEn item) {
        TextView tvCom = helper.getView(R.id.tv_express_com);
        JudgeExpressUtil.analyze(item.getOrder_netsite(), tvCom);



        String takeAddress = String.format("%s%s%s%s", item.getOrder_getProvinceName(),
                item.getOrder_getCityName(),
                item.getOrder_getDistrictName(),
                item.getOrder_getAddress());


        SimplifySpanBuild timeBuild = new SimplifySpanBuild("完成时间：" + mSimpleDateFormat.format(item.getOrder_xdTime()));


        SimplifySpanBuild takeBuild = new SimplifySpanBuild("派件扫描：");

        takeBuild.append(new SpecialTextUnit(String.valueOf(item.getOrder_addOrderNum() + "单"), mContext.getResources().getColor(R.color.pink)));

        SimplifySpanBuild signBuild = new SimplifySpanBuild("签收扫描：");
        signBuild.append(new SpecialTextUnit(String.valueOf(item.getOrder_signOrderNum() + "单"), mContext.getResources().getColor(R.color.green)));


        helper.setText(R.id.tv_express_address, takeAddress)
                .setText(R.id.tv_complete_time, timeBuild.build())
                .setText(R.id.tv_sign_count, signBuild.build())
                .setText(R.id.tv_take_count, takeBuild.build())
                .setText(R.id.tv_phone, item.getOrder_netsite().getNetsite_mobile())
                .setText(R.id.tv_time, mSimpleDateFormat.format(item.getOrder_xdTime()))
                .setText(R.id.tv_task_state,  OrderStateUtil.getOrderStateDes(item.getOrder_status()));

        helper.setText(R.id.tv_deposit, "保证金：" + item.getOrder_depositCost() + "元");
        int cost = item.getOrder_totalCost() == 0 ? item.getOrder_sendOrderNum() * 3 : item.getOrder_totalCost();
        helper.setText(R.id.tv_delivery_charge, "派送费：" + cost + "元");
    }
}
